package com.service.impl;

import java.util.List;

import com.dao.ISchoolDao;
import com.dao.impl.SchoolDao;
import com.entity.School;
import com.service.ISchoolService;
import com.tools.Page;

/**
 * 学校的业务
 * 
 * @author Administrator
 *
 */
public class SchoolService implements ISchoolService {

	private ISchoolDao schoolDao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.service.ISchoolService#add(com.entity.School)
	 */
	@Override
	public boolean add(School school) {

		schoolDao = new SchoolDao(0);
		try {
			boolean save = schoolDao.save(school);
			schoolDao.commit();
			return save;
		} catch (Exception e) {
			e.printStackTrace();
			schoolDao.rollback();
		} finally {
			schoolDao.close();
		}

		return false;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.service.ISchoolService#update(com.entity.School)
	 */
	@Override
	public boolean update(School school) {
		schoolDao = new SchoolDao(0);
		try {
			boolean update = schoolDao.update(school);
			schoolDao.commit();
			return update;
		} catch (Exception e) {
			e.printStackTrace();
			schoolDao.rollback();
		} finally {
			schoolDao.close();
		}

		return false;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.service.ISchoolService#findById(java.lang.String)
	 */
	@Override
	public School findById(String id) {
		schoolDao = new SchoolDao(0);
		try {
			School findById = schoolDao.findById(id);
			schoolDao.commit();
			return findById;
		} catch (Exception e) {
			e.printStackTrace();
			schoolDao.rollback();
		} finally {
			schoolDao.close();
		}

		return null;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.service.ISchoolService#getList(com.tools.Page)
	 */
	@Override
	public List<School> getList(Page page) {
		schoolDao = new SchoolDao(0);
		try {
			// 获得总记录
			page.setCountSize(schoolDao.count());
			List<School> list = schoolDao.getList(page);
			schoolDao.commit();
			return list;
		} catch (Exception e) {
			e.printStackTrace();
			schoolDao.rollback();
		} finally {
			schoolDao.close();
		}

		return null;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.service.ISchoolService#count(com.tools.Page)
	 */
	@Override
	public void count(Page page) {
		schoolDao = new SchoolDao(0);
		try {
			// 获得总记录
			page.setCountSize(schoolDao.count());
			schoolDao.commit();
		} catch (Exception e) {
			e.printStackTrace();
			schoolDao.rollback();
		} finally {
			schoolDao.close();
		}

	}
}
